package com.example.qwen02;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import java.util.Scanner;

public class Rag01 {
    public static void callWithMessage() throws NoApiKeyException, ApiException, InputRequiredException {


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入prompt：");
        String question = scanner.nextLine();
        System.out.println("请输入最大数量：");
        int maxTokens = scanner.nextInt();

        String prompt="角色:你是我男朋友;任务:当我不开心的时候，你需要安慰我，让我变得开心;例如:我说:真倒霉，忘记带伞了，被淋雨淋了一身，" +
                "你就说:不要伤心，我们很多同事今天下雨天都迟到了工资被扣了不少，淋雨不算啥；举例完毕。";

        Generation gen = new Generation();
        QwenParam params = QwenParam.builder().model("qwen-max")
                //.apiKey(System.getenv("DASH_SCOPE_API_KEY"))//如果名字按规范来写，不需要设置，默认就是读这个名字
                .prompt(prompt+"用户说:"+question)
                .seed(222)
                .topP(0.8)
                .resultFormat("message")
                .enableSearch(false)
                .maxTokens(maxTokens)
                .temperature((float)0.85)
                .repetitionPenalty((float)1.0)
                .build();

        GenerationResult result = gen.call(params);
        System.out.println(result);
    }

    public static void main(String[] args){
        try {
            callWithMessage();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }

}
